fix: fix selecting parent of unique nodes#1430
Conversation
📝 WalkthroughWalkthroughThe PR adds a comprehensive federation test case demonstrating unique nodes parent root node selection with a multi-subgraph "zigzag" resolution pattern. It also modifies the parent traversal logic in datasource_filter_visitor to break at external, non-provided parents instead of continuing upward. Changes
Possibly related PRs
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go (1)
20223-20245: Test narrative is stale and contradicts the actual scenario.These comments describe
NodeB/Pool/Pool1/sharedFieldand second-subgraph ownership ofuniqueField, but the test actually modelsNodeA -> Detailand resolvesuniqueFieldfrom the first subgraph. Please align comments with the implemented schema and expected fetches.♻️ Suggested comment cleanup
- // Tests a scenario where the planner must navigate through multiple layers of - // abstract types with `@external` fields to reach an entity whose fields are - // split across subgraphs. Mirrors a real-world pattern where: - // - // - Node (interface) is implemented by NodeA and NodeB - // - NodeA/NodeB declare pool: Pool! as `@external` in the first subgraph - // (to satisfy the Node interface), but Pool is truly owned by the second subgraph - // - Pool (interface) is implemented by Pool1 - // - Pool1.detail: Detail! is `@external` in the first subgraph, owned by the second - // - Detail is an entity with fields split across subgraphs: - // uniqueField → second subgraph only - // sharedField → first subgraph only - // - // Expected execution (zigzag: first → second → first): - // Fetch 0: first subgraph — root nodes query, returns NodeA keys - // Fetch 1: second subgraph — entity-resolve NodeA, traverse pool → Pool1 → detail, - // inline Detail.uniqueField (owned by second subgraph) - // Fetch 2: first subgraph — entity-resolve Detail to get sharedField - // - // Planner confusion: Pool1 appears as an entity in the first subgraph with - // detail `@external`. The planner may incorrectly try to resolve detail through - // the first subgraph's Pool1 entity, not realising it must go via the second - // subgraph's NodeA entity resolution first. + // Regression: ensure parent selection does not stop at an external interface field. + // Scenario: + // - `Query.nodes` is fetched from first subgraph. + // - `NodeA.detail` is external in first subgraph and resolved via second subgraph. + // - `Detail.uniqueField` is then resolved back in first subgraph via entity jump. + // + // Expected execution: first -> second -> first. @@ - // Second subgraph: owns pool on NodeA/NodeB, owns detail on Pool1, - // owns Detail.uniqueField. Detail.sharedField lives only in first subgraph. + // Second subgraph: resolves NodeA.detail and returns Detail keys. @@ - // Fetch 1: entity-resolve NodeA from second subgraph. - // Second subgraph owns pool (non-external on NodeA), Pool1.detail, and Detail.uniqueField, - // so all three can be resolved inline without additional entity fetches. + // Fetch 1: entity-resolve NodeA in second subgraph and return Detail.id. @@ - // Fetch 2: entity-resolve Detail from first subgraph to get sharedField. - // This is the jump back — first subgraph is the only owner of Detail.sharedField. + // Fetch 2: entity-resolve Detail in first subgraph to get uniqueField.Also applies to: 20359-20360, 20475-20477, 20516-20517
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go` around lines 20223 - 20245, The test comments for the federation scenario are stale and misdescribe the implemented schema and expected fetch sequence; update the narrative comments that mention NodeB/Pool/Pool1/sharedField and the ownership of uniqueField so they accurately reflect the actual test implementation (which models NodeA -> Detail and resolves uniqueField from the first subgraph), and adjust the listed expected execution steps to match the real fetch order and ownership (references: Node, NodeA, NodeB, Pool, Pool1, Detail, uniqueField, sharedField and the “zigzag” fetch sequence). Ensure you update all occurrences noted (around the blocks near the ones flagged: the current comment block and the later blocks at the same pattern) so comments align with the schema and expected fetches.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go`:
- Around line 20223-20245: The test comments for the federation scenario are
stale and misdescribe the implemented schema and expected fetch sequence; update
the narrative comments that mention NodeB/Pool/Pool1/sharedField and the
ownership of uniqueField so they accurately reflect the actual test
implementation (which models NodeA -> Detail and resolves uniqueField from the
first subgraph), and adjust the listed expected execution steps to match the
real fetch order and ownership (references: Node, NodeA, NodeB, Pool, Pool1,
Detail, uniqueField, sharedField and the “zigzag” fetch sequence). Ensure you
update all occurrences noted (around the blocks near the ones flagged: the
current comment block and the later blocks at the same pattern) so comments
align with the schema and expected fetches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6be3fa7d-4684-4776-858c-2ee5eaec7da5
📒 Files selected for processing (2)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.gov2/pkg/engine/plan/datasource_filter_visitor.go
…selection-when-use-interfaces
🤖 I have created a release *beep* *boop* --- ## [2.0.0-rc.261](v2.0.0-rc.260...v2.0.0-rc.261) (2026-03-06) ### Bug Fixes * fix selecting parent of unique nodes ([#1430](#1430)) ([fd0e06a](fd0e06a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue with selecting parent of unique nodes <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Tests
Bug Fixes
Checklist